package com.night.xjh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.night.common.entity.xjh.Callback;
import com.night.common.entity.xjh.CallbackType;
import com.night.xjh.mapper.CallbackMapper;
import com.night.xjh.mapper.CallbackTypeMapper;
import com.night.xjh.service.CallbackService;
import com.night.xjh.service.CallbackTypeService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName: CallbackServiceImpl
 * @Description: //TODO
 * @author: xjh
 * @date: 2022/10/21-15:14
 * @version: v1.0
 */
@Service
public class CallbackTypeServiceImpl implements CallbackTypeService {
    @Resource
    private CallbackTypeMapper callbackTypeMapper;
    @Resource
    private RedisTemplate redisTemplate;
    public void add(CallbackType callbackType) {
        callbackTypeMapper.add(callbackType);
    }

    public void delete(int id) {
        callbackTypeMapper.deleteById(id);
    }

    public void update(CallbackType callbackType) {
        callbackTypeMapper.update(callbackType);
    }

    public List<CallbackType> getAll() {
        List<CallbackType> redisType = (List<CallbackType>) redisTemplate.opsForValue().get("callbackType-getAll");
        if (redisType != null)
            return redisType;
        List<CallbackType> list=callbackTypeMapper.getAll();
        redisTemplate.opsForValue().set("callbackType-getAll", list, 60, TimeUnit.SECONDS);
        return list;
    }

    public CallbackType getById(int id) {
        return callbackTypeMapper.getById(id);
    }

    public List<CallbackType> getByName(String name) {
        List<CallbackType> list=callbackTypeMapper.getByName(name);
        return list;
    }
}
